import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/model/user_model.dart';

// 头像角色昵称
class AvatarRoleName extends StatelessWidget {
  final UserModel? model;

  const AvatarRoleName({
    Key? key,
    this.model,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(left: 10,right: 10),
      height: 60,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _avatar(),
          _btn(),
        ],
      ),
    );
  }

  /// 头像
  Widget _avatar() {
    return Row(
      children: [
        Container(
          width: 34,
          height: 34,
          decoration: BoxDecoration(
            color: AppColors.page,
            borderRadius: BorderRadius.circular(17),
          ),
          child: ClipOval(
            child: FadeInImage.assetNetwork(
              placeholder: 'assets/images/common/lazy-1.png',
              image: model!.p!,
              fit: BoxFit.cover,
            ),
          ),
        ),
        SizedBox(width: 8,),
        _centerview(),
      ],
    );
  }

  /// 中间内容
  Widget _centerview() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(height: 12,),
        Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Text(
              model!.n!,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                fontSize: 13,
                fontWeight: FontWeight.bold,
                color: AppColors.black,
              ),
            ),
            SizedBox(width: 8,),
            Text(
              'LV.${model!.lv.toString()}',
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                  fontSize: 11,
                  color: AppColors.yellow,
                  fontStyle: FontStyle.italic,
                  fontWeight: FontWeight.bold
              ),
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Text(
              '${model!.followers_count_text! +' · ' + model!.recipes_count_text!.toString()}',
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                  fontSize: 12,
                  color: AppColors.qianTextColor,
              ),
            ),
          ],
        )
      ],
    );
  }

  /// 关注按钮
  Widget _btn() {
    return SizedBox(
      width: 60,
      height: 28,
      child: TextButton(
        onPressed: () => print(''),
        child: Text(
          '关注',
          style: TextStyle(
            color: Colors.black,
            fontSize: 12,
            fontWeight: FontWeight.bold,
          ),
        ),
        // color: Colors.amber,
        // shape: RoundedRectangleBorder(
        //     side: BorderSide(
        //       color: Colors.amber,
        //       width: 0.5,
        //     ),
        //     borderRadius: BorderRadius.circular(15)),
      ),
    );
  }

}